package com.burstly.lib.component.networkcomponent.burstly.html.mraid;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build.VERSION;
import android.os.Handler;
import android.view.KeyEvent;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.burstly.lib.component.networkcomponent.IActivityLifeCycleAware;
import com.burstly.lib.component.networkcomponent.burstly.html.LoadingAwareWebView;

@TargetApi(11)
class ContentLoaderWebView extends LoadingAwareWebView
  implements IActivityLifeCycleAware
{
  volatile boolean mCancelled;
  private ChromeClient mChromeClient;
  IWebContentLoadedListener mContentLoaderListener;
  private WebClient mWebClient;

  ContentLoaderWebView(Context paramContext)
  {
    super(paramContext);
    getSettings().setJavaScriptEnabled(false);
    this.mChromeClient = new ChromeClient(null);
    setWebChromeClient(this.mChromeClient);
    this.mWebClient = new WebClient(null);
    setWebViewClient(this.mWebClient);
  }

  void cancelLoading()
  {
    this.mCancelled = true;
    this.mWebClient.cancel();
    destroy();
  }

  boolean isCancelled()
  {
    return this.mCancelled;
  }

  public void onDestroy(Activity paramActivity)
  {
    destroy();
  }

  public boolean onKey(Activity paramActivity, int paramInt, KeyEvent paramKeyEvent)
  {
    return false;
  }

  public void onPause(Activity paramActivity)
  {
    if (Build.VERSION.SDK_INT > 10)
      onPause();
  }

  public void onResume(Activity paramActivity)
  {
    if (Build.VERSION.SDK_INT > 10)
      onResume();
  }

  void setContentLoaderListener(IWebContentLoadedListener paramIWebContentLoadedListener)
  {
    this.mContentLoaderListener = paramIWebContentLoadedListener;
  }

  private class ChromeClient extends WebChromeClient
  {
    private ChromeClient()
    {
    }

    public boolean onJsAlert(WebView paramWebView, String paramString1, String paramString2, JsResult paramJsResult)
    {
      ContentLoaderWebView.IWebContentLoadedListener localIWebContentLoadedListener = ContentLoaderWebView.this.mContentLoaderListener;
      if ((localIWebContentLoadedListener != null) && (!ContentLoaderWebView.this.mCancelled))
      {
        if ((paramString2 == null) || ("null".equals(paramString2)))
          break label75;
        localIWebContentLoadedListener.onLoad("<html>" + paramString2 + "</html>");
      }
      while (true)
      {
        paramJsResult.confirm();
        return true;
        label75: localIWebContentLoadedListener.onFailedToLoad();
      }
    }
  }

  static abstract interface IWebContentLoadedListener
  {
    public abstract void onFailedToLoad();

    public abstract void onLoad(String paramString);
  }

  private class WebClient extends WebViewClient
    implements Runnable
  {
    private final Handler mUiHandler = new Handler();

    private WebClient()
    {
    }

    void cancel()
    {
      this.mUiHandler.removeCallbacks(this);
    }

    public void onPageFinished(WebView paramWebView, String paramString)
    {
      if (!ContentLoaderWebView.this.mCancelled)
        this.mUiHandler.postDelayed(this, 1500L);
    }

    public void onPageStarted(WebView paramWebView, String paramString, Bitmap paramBitmap)
    {
      cancel();
    }

    public void run()
    {
      ContentLoaderWebView.this.getSettings().setJavaScriptEnabled(true);
      ContentLoaderWebView.this.loadUrl("javascript:var html = null; try{html = window.document.getElementsByTagName('html')[0].innerHTML}catch(e){};alert(html);");
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.mraid.ContentLoaderWebView
 * JD-Core Version:    0.6.2
 */